package code.c08;

import java.util.*;

/**
 * @author thinkpad - 83start
 * @version v1.0
 * @create 2022/10/20 10:34
 * @package code.c08
 * @description 文件说明
 */

public class SetTest {
    public static void main(String[] args) {
//        Set<Integer> set = new TreeSet<>();
/*        HashSet<Integer> set = new HashSet<>();
        int[] as = {1,2,8,4,3,3,3,3,2,100,200,1000};

        for (int i = 0; i < as.length; i++) {
            set.add(as[i]);
        }

        for (Integer a:set) {
            System.out.println(a);
        }*/


        // 实现 TreeSet 的比较器
        TreeSet<Student> studentSet = new TreeSet<>(new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                return o1.getS_name().compareTo(o2.getS_name());
            }
        });
        studentSet.add(new Student(101,"baoma"));
        studentSet.add(new Student(102,"aodi"));
        studentSet.add(new Student(103,"lanbojini"));

        Iterator<Student> iterator = studentSet.iterator();
        while (iterator.hasNext()){
            System.out.println(iterator.next());
        }
    }
}
